//DateTimeCellRenderer.java
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.util.Date;
import java.awt.*;
import java.text.SimpleDateFormat;

/*
 * This class makes a Long look like a date in the JTable. 
 */

public class DateTimeCellRenderer implements TableCellRenderer {

   private JLabel alabel = new JLabel();
   private SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy HH:mm");

   public DateTimeCellRenderer() {
      alabel.setOpaque(true);
   }

   public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                                                  boolean hasFocus, int row, int column) {
      Long L = (Long)value;
      Date d = new Date(L.longValue());
      alabel.setText(sdf.format(d));
      alabel.setFont(new Font("Courier", Font.BOLD, 16));
      alabel.setHorizontalAlignment(JLabel.CENTER);
      
      if (isSelected) {
        alabel.setBackground(table.getSelectionBackground()); 
      }
      else {
        alabel.setBackground(table.getBackground());
      }
      return alabel;
   }
}
